package com.link2room.ironhide.facade.impl;

import com.link2room.common.constant.DefaultValue;
import com.link2room.common.service.ICommonService;
import com.link2room.common.util.ClassConverUtil;
import com.link2room.ironhide.dto.result.base.L2RCommissionDto;
import com.link2room.ironhide.entity.L2RCommission;
import com.link2room.ironhide.dto.param.inside.L2RCommissionInsideParamDto;
import com.link2room.ironhide.facade.ICommissionFacadeService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * Created by sss on 2016/12/9.
 */
@Component("commissionFacadeService")
public class CommissionFacadeServiceImpl implements ICommissionFacadeService {
    @Resource
    private ICommonService commonService;

    @Override
    public L2RCommissionDto findCommission(L2RCommissionInsideParamDto l2RCommissionInsideParamDto)throws Exception{
        L2RCommission queryC=new L2RCommission();
        queryC.setLhotelGroupCode(l2RCommissionInsideParamDto.getLhotelGroupCode());
        queryC.setPbChannel(l2RCommissionInsideParamDto.getPbChannel());
        queryC.setResType(l2RCommissionInsideParamDto.getResType());
        L2RCommission l2rCommission = commonService.findOneEQ(L2RCommission.class, queryC);
        if(l2rCommission==null){
            l2rCommission=new L2RCommission();
            l2rCommission.setLhotelGroupCode(l2RCommissionInsideParamDto.getLhotelGroupCode());
            l2rCommission.setCommCode(DefaultValue.DEFAULT_COMM_CODE);
            l2rCommission.setComm(new BigDecimal(1));
        }
        return ClassConverUtil.copyPropertiesToDto(l2rCommission, L2RCommissionDto.class,false);
    }
}
